Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coverage blocks overlapping #3575

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Slava0135
Copy link
Contributor

Problem

Resolves #3559.

Solution

Remove block if it includes any other block.

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.35%. Comparing base (d9a6a7c) to head (794f204).
Report is 15 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3575      +/-   ##
==========================================
- Coverage   85.79%   85.35%   -0.45%     
==========================================
  Files         330      333       +3     
  Lines       38536    39006     +470     
==========================================
+ Hits        33062    33292     +230     
- Misses       3928     4144     +216     
- Partials     1546     1570      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pkg/neotest/coverage.go Outdated Show resolved Hide resolved
pkg/neotest/coverage.go Outdated Show resolved Hide resolved
@Slava0135
Copy link
Contributor Author

Fixed issues and made it a single commit

)

func resetCoverage() {
rawCoverage = make(map[util.Uint160]*scriptRawCoverage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map is protected by mutex, so at least we need to use mutex. Also, these tests prohibit NeoGo from using contract coverage in the project; we either need to document this or to change the test structure to skip them if contract coverage is enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make new map, save old map and then restore original map in Cleanup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won’t work if tests run in parallel.

pkg/neotest/coverage.go Outdated Show resolved Hide resolved
continue
}
// outer interval start must be before inner interval start.
if !(outer.StartLine < inner.StartLine || outer.StartLine == inner.StartLine && outer.StartCol <= inner.StartCol) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this algorithm is that we can't just remove all outer intervals, otherwise coverage for some parts of code is lost and the result looks strange a bit. Consider neofs-contracts as an example, here's the result with the old implementation:
image
And here's the result with the overlaps removal:
image

return runtime.CheckWitness( is an outer interval and it's just removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not quite sure why the first call to runtime.CheckWitness is marked as not covered, although it should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not quite sure why the first call to runtime.CheckWitness is marked as not covered, although it should be.

Pretty sure, its because there is no SeqPoint for it

Copy link
Contributor Author

@Slava0135 Slava0135 Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked how Go itself handles statement coverage and it seems like it takes a line as a whole (except for conditions where paths can diverge, though still counts for outer function if inner function panics). So we could keep outer block if its one the same line as inner (both are one-liners), but remove outer block if its multi-line?

Copy link
Member

@AnnaShaleva AnnaShaleva Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give an example of contract with test where coverage blocks are overlapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PutNamed function in container contract.

@Slava0135
Copy link
Contributor Author

In container.go many statements (functions calls) are not tracked. Probably would need to generate more SeqPoints for these.
image

@AnnaShaleva
Copy link
Member

Probably would need to generate more SeqPoints for these.

We firstly need to check the debug info for this contract, and if debug info is really missing these sequence points then it’s a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Neotest coverage blocks are overlapping sometimes
2 participants